<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

function odbcLink(){
    $mssqldriver = '{ODBC Driver 11 for SQL Server}';
    $hostname='192.168.0.222';
    $dbname='QPGameUserDB';
    $username='gameuser';
    $password='123456';
    $pdo = new PDO("odbc:Driver=$mssqldriver;Server=$hostname;Database=$dbname", $username, $password);
    return $pdo;
}

function odbcLink2(){
    $mssqldriver = '{ODBC Driver 11 for SQL Server}';
    $hostname='192.168.0.222';
    $dbname='QPServerInfoDB';
    $username='gameuser';
    $password='123456';
    $pdo = new PDO("odbc:Driver=$mssqldriver;Server=$hostname;Database=$dbname", $username, $password);
    return $pdo;
}



/**
 * 对取出的数据进行转码
 *
 * @param $data $data 是需转码数据
 * @return mixed
 */
function washData($data){
    if(!empty($data)){
        foreach ($data as $k=>$value){
            $data[$k]['NickName']=iconv("gbk", "utf-8",$data[$k]['NickName']);
            $data[$k][4]=iconv("gbk", "utf-8",$data[$k][4]);
            $data[$k]['memo']=iconv("gbk", "utf-8",$data[$k]['memo']);
            $data[$k]['11']=iconv("gbk", "utf-8",$data[$k]['11']);
        }
    }

    return $data;

}

/**
 * 处理数字
 * @param $param
 * @return string
 */
function numberFormat($param){
    if($param == ""){
        return "0";
    }else{
        return $param + 0;
    }
}


//处理参数值 存储参数默认为 null 的时候
function nullParamFormat($param){

    if($param == ""){
        $param = 'null';
    }else{
        $param = "'".$param."'";
    }

    return $param;
}

//处理参数值 存储参数默认为 -1 的时候
function paramFormat($param){

    if($param == ""){
        $param = '-1';
    }else{
        $param = "'".$param."'";
    }

    return $param;
}


//获取IP地址
function getIPaddress(){
    $IPaddress='';
    if(isset($_SERVER)){
        if(isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
            $IPaddress = $_SERVER["HTTP_X_FORWARDED_FOR"];
        }else if(isset($_SERVER["HTTP_CLIENT_IP"])){
            $IPaddress = $_SERVER["HTTP_CLIENT_IP"];
        }else{
            $IPaddress = $_SERVER["REMOTE_ADDR"];
        }
    }else{
        if (getenv("HTTP_X_FORWARDED_FOR")){
            $IPaddress = getenv("HTTP_X_FORWARDED_FOR");
        }else if(getenv("HTTP_CLIENT_IP")){
            $IPaddress = getenv("HTTP_CLIENT_IP");
        }else{
            $IPaddress = getenv("REMOTE_ADDR");
        }
    }
    return $IPaddress;
}

/*
	 * 调用dll方法
	 * 参数：
	 * 		$requestType：操作码，
	 *      $UserId：用户ID，
	 * 		$byLimitType： 暂时不用，
	 * 		$msg：内容，
	 * 		$do：操作类型
	 */
function transferDLL($requestType, $UserId, $byLimitType, $msg, $do){

    $Server = new com("WebClient.Client");
    //$ip = "172.17.24.47";//本地服务器
    $ip="192.168.1.222";
    $Server -> Connect($ip,9010);

    $Server -> SetAdministratorsInfo("hzq", "e10adc3949ba59abbe56e057f20f883e");

    if($do == "update"){

        //一般操作
        $Server -> SendNormaperate($requestType);


    }else if($do == "send"){

        $msg = iconv("utf-8", "GB2312", $msg);

        //发送通告
        $Server -> SendMsg($requestType, $UserId, $byLimitType, $msg);

    }

    //echo "1";
    return 1;

}

